package casper.alpha;

import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import casper.alpha.utils.CasperQuery;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;

public class CasperStaticQueryPoints {
	
	private static final double GRIDSIZE = 5.0;
	private static final double DELTA = 1.0;
	
	private Map<String, List<Coordinate>> 	publicDataCSQP = new Hashtable<String, List<Coordinate>>();
	private Map<String, List<Geometry>> 	privateDataCSQP = new Hashtable<String, List<Geometry>>();
	
	private CasperStaticQueryPoints() {
		
	}
	
	private static CasperStaticQueryPoints csqp = null;
	
	public static CasperStaticQueryPoints defaultCSQP() {
		if(csqp == null) {
			csqp = new CasperStaticQueryPoints();
		}
		return csqp;
	}
	
	public void clearPublicCSQP () {
		publicDataCSQP.clear();
	}
	
	public void clearPrivateCSQP () {
		privateDataCSQP.clear();
	}
	
	public void clearCSQP () {
		clearPrivateCSQP();
		clearPublicCSQP();
	}
	
	private Coordinate nearestCSQP(Coordinate c) {
		return null;
	}
	
	public List<Coordinate> publicStaticQuery(Coordinate c) {
		String key = nearestCSQP(c).toString();
		if(publicDataCSQP.containsKey(key)) {
			return publicDataCSQP.get(key);
		}
		List<Coordinate> knns = new CasperQuery().getPublicKNNs(nearestCSQP(c));
		publicDataCSQP.put(key, knns);
		return knns;
	}
	
	public List<Geometry> privateStaticQuery(Coordinate c, boolean reduce) {
		String key = nearestCSQP(c).toString();
		if(privateDataCSQP.containsKey(key)) {
			return privateDataCSQP.get(key);
		}
		List<Geometry> knns = new CasperQuery().getPrivateKNNs(nearestCSQP(c), reduce);
		privateDataCSQP.put(key, knns);
		return knns;
	}
}
